﻿using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace System.Data.Cassandra.Configuration
{
    public class ServerElementCollection : ConfigurationElementCollection
    {
        protected override ConfigurationElement CreateNewElement()
        {
            return new ServerElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((ServerElement)element).Name;
        }

        public ServerElement this[int index]
        {
            get
            {
                return (ServerElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        public List<String> ToList()
        {
            return this.Cast<ServerElement>().Select(server => server.Name).ToList();
        }
    }
}